#!/bin/bash
#此脚本用于编译Android arm64环境下的Bash，需在Linux amd64环境下运行。
wget -O android-ndk.zip https://googledownloads.cn/android/repository/android-ndk-r27d-linux.zip
unzip -o android-ndk.zip 
sudo resolvectl flush-caches
GIT_SSH_VARIANT=none git clone https://gitee.com/xc1984759471/bash
cd bash

make clean
make distclean
export NDK_HOME=$(pwd)/../android-ndk-r27d #安卓NDK路径
export PATH=$NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin:$PATH
export TOOLCHAIN=$NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android30-clang
export SYSROOT=$NDK_HOME/sysroot


#CC=clang CXX=clang++ \
#./configure --host=aarch64-linux-gnu --enable-static-link --without-bash-malloc
#make -j4

CC=$NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android30-clang CXX=$NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android30-clang++ \
CROSS_COMPILE=aarch64-linux-android30 \
CFLAGS="--target=aarch64-linux-android30 -Dstrchrnul=my_strchrnul " \
CXXFLAGS="--target=aarch64-linux-android30 -Dstrchrnul=my_strchrnul " \
LDFLAGS="--target=aarch64-linux-android30"  \
./configure --host=aarch64-linux-android30 --enable-static-link  --without-bash-malloc --disable-nls --enable-job-control --enable-process-substitution
make -j4
#$NDK_HOME/ndk-build -j4
mv bash bash.elf
cp bash.elf ..
cd ..
rm -rf bash bash.tar.xz android-ndk.zip android-ndk-r27d
mv bash.elf bash